package llvmir.value.structure;

import llvmir.type.PointerType;
import llvmir.type.Type;
import llvmir.value.User;
import llvmir.value.Value;

public class GlobalVariable extends User {
    public enum VType {
        CONSTANT,
        VARIABLE;

        @Override
        public String toString() {
            switch (this) {
                case CONSTANT:
                    return " constant";
                default:
                    return " global";
            }
        }
    }

    // 全局变量是变量还是常量
    private VType vType;

    // type可能是int32/int8/[x * int32]/[x * int8]
    public GlobalVariable(String name, Type type, VType vType, Value value) {
        super("@" + name, new PointerType(type));
        this.vType = vType;
        this.addOperand(value);
        value.getUsers().add(this);
    }

    public VType getVType() {
        return vType;
    }

    @Override
    public String toString() {
        return this.getName() + " = dso_local" +
                this.getVType() + " " + ((PointerType) this.getType()).getPoint() +
                this.getFirstOperand();
    }
}
